package com.example.test.controller;

import com.example.test.service.IUserService;
import com.example.test.support.UserSupport;
import com.example.test.vo.ResponseVo;
import com.example.test.vo.UserVo;

import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @Autowired
    private UserSupport userSupport;

    @GetMapping("/one")
    public ResponseVo<UserVo> getOneUser(HttpServletRequest request, @RequestParam Integer userId) {
//        Integer userId = userSupport.getUserId(request);
        UserVo userInfo = userService.getUserInfo(userId);

        return ResponseVo.success(userInfo);
    }

    @RequestMapping("/list")
    public ResponseVo<List<UserVo>> getUserInfo(){
        List<UserVo> list = userService.getUserList();
        return ResponseVo.success(list);
    }

    @PostMapping("/pagelist")
    public ResponseVo<PageInfo<UserVo>> list(@RequestParam(required = false) String username,
                                             @RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                             @RequestParam(required = false,defaultValue = "10") Integer pageSize){
        System.out.println("controller:" + username);
        return userService.list(username, pageNum, pageSize);
    }
}